/*
 * @Author: wangzhijian
 * @Date: 2025-04-09 15:20:36
 * @LastEditTime: 2025-04-09 23:01:18
 */
import { CalculatorParams, CalculationResult, ApiResponse } from '../types/calculator';

const API_BASE_URL = 'http://localhost:3000';

export async function calculateY(params: CalculatorParams): Promise<ApiResponse<CalculationResult>> {
    try {
        const response = await fetch(`${API_BASE_URL}/calculate-y`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(params),
        });

        const data = await response.json();
        return data;
    } catch () {
        return {
            success: false,
            error: '请求失败，请稍后重试'
        };
    }
}

export async function calculateOff(params: CalculatorParams): Promise<ApiResponse<CalculationResult>> {
    try {
        const response = await fetch(`${API_BASE_URL}/calculate-off`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(params),
        });

        const data = await response.json();
        return data;
    } catch () {
        return {
            success: false,
            error: '请求失败，请稍后重试'
        };
    }
} 